require("../../assets/css/index.less");
// require("../../assets/css/property.less");
require("./login.less");
// let https = require("../../utils/https.js");
// let http = require("../../utils/http.js");
let validator = require("../../utils/validator.js");
let https = require("../../utils/https.js");
let dom = require("../../utils/dom.js");
import "../../assets/lib/iconfonts/iconfont.css";
import CaptchaMini from "captcha-mini";
dom.ready(function () {
    dom.getEle(".login-top").addEventListener("click", function () {
        location.href = "register.html";
    });
    let captcha1 = new CaptchaMini();
    let codejs;
    captcha1.draw(document.querySelector("#captcha1"), (r) => {
        // console.log(r, "验证码1");
        codejs = r;
        codejs = codejs.toLowerCase();
    });
    dom.getEle("#loginBtn").addEventListener("click", function () {
        let account = dom.getEle(".phone").value;
        let vcode = dom.getEle("#login-code").value;
        let password = dom.getEle(".pwd").value;
        let okPwd = dom.getEle(".okPwd").value;
        if (account == "") {
            alert("请输入手机号");
            return;
        } else if (!validator.isphone(account)) {
            alert("请输入正确的手机号");
            return;
        } else if (vcode == "") {
            alert("请输入验证码码");
            return;
        } else if (!vcode.toLowerCase() == codejs) {
            alert("请输入正确的验证码");
            return;
        } else if (password == "") {
            alert("请输入密码");
            return;
        } else if (!validator.ispwd(password)) {
            alert("请输入正确密码");
        } else if (!password == okPwd) {
            alert("两次密码不一样");
        } else {
            https.post("/api/user/isExist", { account }, function (res) {
                // 如果账号是否存在
                if (res.errno == 0) {
                    https.post(
                        "/api/user/register",
                        { account, password },
                        function (res) {
                            // 如果账号是否存在
                            if (res.errno == 0) {
                                alert("注册成功");
                                location.href = "register.html";
                            } else {
                                alert(注册失败);
                            }
                        }
                    );
                } else {
                    alert("账号已存在");
                }
            });
        }
    });
    // https.get("/api/shared/province", function (res) {
    // 	console.log(res);
    // });
});
